var is_run = false;
var box = $('.box').eq(0);
var box1 = $('.box')[0];
var detail_pub = $('.detail_pub').eq(0);
var detail_pub1 = $('.detail_pub')[0];
var click_x, click_y, move_x, move_y, now_x, now_y;
var away = parseInt(window.screen.width) * 0.3;
var p_lis = document.getElementsByClassName('p_lis');
var roll_abs = document.getElementsByClassName('roll_abs')[0];

console.log();

//点击奖品跳至奖品页面
$('.prize').click(function () {
	$('.prize_page').css("display", "block");
	$('.active_page').css("display", "none");
})
//关闭奖品页面，跳至活动页面
$('.prize_back').click(function () {
	$('.prize_page').css("display", "none");
	$('.active_page').css("display", "block");
})
//点击活动说明跳至活动说明页面
$('.active_description').click(function () {
	$('.description_page').css("display", "block");
	$('.active_page').css("display", "none");
})
// 活动说明页面跳至活动页面
$('.des_back').click(function () {
	$('.description_page').css("display", "none");
	$('.active_page').css("display", "block");
})
// 点击卡片跳至详情页面
$('.box').on("click", function () {
	$('.detail_page').css("display", "block");
	$('.detail_pub').eq(0).css('display', 'block');

	//	$('.active_page').css("display", "none");
})
// 详情页跳至活动页面
$('.detail_img').click(function () {
	$('.detail_page').css("display", "none");
	$('.active_page').css("display", "block");
})
// 详情页面点击更多，显示介绍全部内容
$('.more').click(function () {
	$(".detail_con p").css("display", "block");
	$(".more").text(" ");
})

$('.unlike').click(function () {
	$('.active_page').css('display', 'block');
	$('.detail_page').css('display', 'none');
	var delete_time = setTimeout(function () {
		(function () {
			box.css('transition', '1s')
				.css('transform', 'translate(-180%,50%) rotate(9deg)');
			$('.box').eq(1).css('transform', 'scale(1)')
				.css('transition', 'transform 0.5s linear');
			var bottom_l_time = setTimeout(function () {
				box.remove();
				box1 = $('.box')[0];
				box = $('.box').eq(0);
				detail_pub.remove();
				detail_pub1 = $('.detail_pub')[0];
				detail_pub = $('.detail_pub').eq(0);
				clearTimeout(bottom_l_time);
			}, 600);
		})();
		clearTimeout(delete_time);
	}, 500);
});

$('.like').click(function () {
	$('.active_page').css('display', 'block');
	$('.detail_page').css('display', 'none');
	var delete_time = setTimeout(function () {
		(function () {
			box.css('transition', '1s')
				.css('transform', 'translate(130%,50%) rotate(-9deg)');
			$('.box').eq(1).css('transform', 'scale(1)')
				.css('transition', 'transform 0.5s linear');
			var bottom_r_time = setTimeout(function () {
				box.remove();
				box1 = $('.box')[0];
				box = $('.box').eq(0);
				detail_pub.remove();
				detail_pub1 = $('.detail_pub')[0];
				detail_pub = $('.detail_pub').eq(0);
				clearTimeout(bottom_r_time);
			}, 600);
		})();
		clearTimeout(delete_time);
	}, 500);
});

//控制高度
var innerHeight = window.innerHeight,
	bodyHeight = document.getElementsByClassName("web")[0],
	clientHeight = document.getElementsByTagName("html")[0].clienltHeight;
if (innerHeight < clientHeight) {
	console.log(innerHeight);
	console.log(document.getElementsByTagName("html"));
	bodyHeight.setAttribute("style", "height:" + clientHeight + "px");
}


$('.index_pull').on("touchstart", function (e) {
	is_run = true;
	/*点下时，允许鼠标移动，并获取坐标*/
	click_x = e.changedTouches[0].clientX;
	click_y = e.changedTouches[0].clientY;
	console.log(box.length);
	if (box.length == 0) {
		console.log(box);
		box1.style="";
	}
	box1.style.willChange = 'transform';
	box.css('transition', 'all 0s');
	// alert(111);

	$(".web").on('touchmove', function (e) {
		e.preventDefault();
	});

});
document.addEventListener("touchmove", function (e) {
	if (is_run) {
		/*获取移动时的坐标*/
		move_x = e.changedTouches[0].clientX;
		move_y = e.changedTouches[0].clientY;
		/*相减*/
		now_x = move_x - click_x;
		now_y = move_y - click_y;

		box1.style.left = now_x + 'px';
		box1.style.top = now_y + 'px';
		$('.box').eq(1).css('transform', 'scale(1)')
			.css('transition', 'transform 0.5s linear');
		if (now_x > 0) {
			box1.style.transform = 'translate3d(0,0,0) rotate(-3deg)';
		} else if (now_x < 0) {
			box1.style.transform = 'translate3d(0,0,0) rotate(3deg)';
		}
	}
});
document.addEventListener("touchend", function (e) {
	is_run = false;
	box1.style.willChange = 'auto';

	$(".web").unbind("touchmove");

	if (parseInt(box.css('left')) < -away) {
		box.remove();
		box1 = $('.box')[0];
		box = $('.box').eq(0);
		detail_pub.remove();
		detail_pub1 = $('.detail_pub')[0];
		detail_pub = $('.detail_pub').eq(0);
	} else if (parseInt(box.css('left')) > away) {
		box.remove();
		box1 = $('.box')[0];
		box = $('.box').eq(0);
		detail_pub.remove();
		detail_pub1 = $('.detail_pub')[0];
		detail_pub = $('.detail_pub').eq(0);
	} else {
		box.css('transition', '0.26s linear');
		box1.style.transform = 'translate3d(0,0,0) rotate(0deg)';
		box1.style.top = 0 + 'px';
		box1.style.left = 0 + 'px';
		$('.box').eq(1).css('transform', 'scale(0.97) translate3d(0,10px,0)');
	}
});
/**左**/
function click_l() {
	$('.bottom_l').click(function () {
		box.css('transition', '1s')
			.css('transform', 'translate(-180%,50%) rotate(9deg)');
		$('.box').eq(1).css('transform', 'scale(1)')
			.css('transition', 'transform 0.5s linear');
		var bottom_l_time = setTimeout(function () {
			box.remove();
			box1 = $('.box')[0];
			box = $('.box').eq(0);
			detail_pub.remove();
			detail_pub1 = $('.detail_pub')[0];
			detail_pub = $('.detail_pub').eq(0);
			clearTimeout(bottom_l_time);
		}, 600);
	});

}
click_l();
/**左**/
/**右**/
function click_r() {
	$('.bottom_r').click(function () {
		box.css('transition', '1s')
			.css('transform', 'translate(130%,50%) rotate(-9deg)');
		$('.box').eq(1).css('transform', 'scale(1)')
			.css('transition', 'transform 0.5s linear');
		var bottom_r_time = setTimeout(function () {
			box.remove();
			box1 = $('.box')[0];
			box = $('.box').eq(0);
			detail_pub.remove();
			detail_pub1 = $('.detail_pub')[0];
			detail_pub = $('.detail_pub').eq(0);
			clearTimeout(bottom_r_time);
		}, 600);
	});

}
click_r();
/**右**/

/** 详情页面控制星星**/
for (i = 0; i < Math.round($('.score').text()); i++) {
	$('.detail_con ul li').eq(i).css("display", "block");
}